Skip to content

Conversation

Copy link

Copilot AI commented Sep 5, 2025

This PR adds Java language support to the VSCode Regex Previewer extension, allowing users to preview regex matches for Java code alongside the existing support for JavaScript, TypeScript, PHP, Vue, and Haxe.

Changes Made

Language Support

  • Added java to the activation events in package.json to enable the extension for Java files
  • Updated the extension description to mention Java support
  • Added java to the supported languages array in the extension code

Java Regex Pattern Detection

  • Created a comprehensive Java-specific regex pattern that detects regex usage in:
    • Pattern.compile("regex") calls
    • String method calls: .matches("regex"), .replaceAll("regex", replacement), .replaceFirst("regex", replacement), .split("regex")
  • The pattern correctly handles escaped characters and complex regex patterns commonly used in Java

Code Changes

  • Enhanced the createRegexMatch function to handle Java's string-based regex patterns (no flags like other languages)
  • Updated the getRegexRegex function to return the appropriate regex pattern for Java files
  • Added comprehensive test coverage for various Java regex patterns

Example Usage

The extension now works with Java code like:

import java.util.regex.Pattern;

public class Example {
    public void testRegex() {
        // All of these will show regex previews
        Pattern pattern = Pattern.compile("\\d+");
        String email = Pattern.compile("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}");
        
        String text = "Hello World 123";
        boolean matches = text.matches("\\w+\\s\\w+\\s\\d+");
        String result = text.replaceAll("\\d+", "XXX");
        String[] parts = text.split("\\s+");
    }
}

When editing Java files, users can now:

  1. See regex patterns highlighted with code lenses
  2. Click "Test Regex..." to open the side-by-side preview
  3. Test their regex patterns against sample text in real-time
  4. Use the same toggle functionality (Ctrl+Alt+M / ⌥⌘M) as with other supported languages

This enhancement makes the extension more useful for Java developers who work with regular expressions in their code.

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] add support for Java Add Java support to Regex Previewer extension Sep 5, 2025
Copilot AI requested a review from chrmarti September 5, 2025 12:26
Copilot finished work on behalf of chrmarti September 5, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants